package com.lxl.message;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

class TemplateStringUtils {
    //去掉所有空格
    static String removeBlank(String content) {
        String dest = null;
        if (content!=null) {
            Pattern p = Pattern.compile("\\s*|\t|\r|\n");
            Matcher m = p.matcher(content);
            dest = m.replaceAll("");
        }
        return dest;
    }
    //去掉首尾的括号
    static String removeBracket(String content){
        if (content.startsWith("{") && content.endsWith("}"))
            return content.substring(1,content.length()-1);
        else
            return content;
    }

    static String getBracketedStr(String content){
        return content.substring(1,content.length()-1);
    }

    //取第一个=号分成K-V
    static String[] getKeyAndValue(String content){
        String[] maps = new String[2];
        int index = content.indexOf('=');
        if (index >= 0){
            maps[0] = content.substring(0, index);
            maps[1] = content.substring(index+1, content.length());
        }

        return maps;
    }

    static boolean isBracketed(String content){
        return content.startsWith("{") && content.endsWith("}");
    }

    static boolean isSysTag(String content){
        return content.startsWith("#") && content.endsWith("#");
    }

    static boolean isKeyTag(String content){
        return content.startsWith("$") && content.endsWith("$");
    }
}
